<template>
	<div class="mine-wallet">
        <myNavbar title="会员卡"></myNavbar>
		<div class="saveCard-top" id="saveCard-top">
			<div class="saveCard-bg">
				<image class="saveCard-bg-image" src="http://cdn.rzico.com/v4.0/wallet-cardBg.png"></image>
				<text class="saveCard-text1">可用余额</text>
				<text class="saveCard-text2">￥{{ balance }}</text>
				<!-- <div class="saveCard-text3">有效期至 2019/12/31</div> -->
			</div>
		</div>
		<scroller>
			<div v-if="showDetail">
				<div class="saveCard-bottom pd-L20 pd-R20">
					<div v-for="item in saveCardDetail">
						<div class="saveCard-bottom-list">
							<image class="saveCard-bottom-list-image" :src="item.icon"></image>
							<!-- <image src="http://cdn.rzico.com/v4.0/{{item.icon}}"></image> -->
							<div class="bottom-item">
								<div class="saveCard-bottom-list-top">
									<text class="saveCard-bottom-list-top1">{{ item.tag }} - {{ item.remark }}</text>
									<text :class="['saveCard-bottom-list-top2', [item.isIncome == true ? 'redColor' : '']]">{{ item.isIncome == true ? '+' : '-' }} ￥{{ item.account }}</text>
								</div>
								<div class="saveCard-bottom-list-bottom">
									<text>{{ item.date }}</text>
									<text>余额：{{ item.balance }}</text>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="saveCard-none" v-else>
				<image class="saveCard-none-image " src="http://cdn.rzico.com/v4.0/footprint-none.png"></image>
				<div class="saveCard-none-text">暂无消费记录</div>
			</div>
			<loading v-if="showDetail" class="loading" @loading="onloading" :display="loadinging ? 'show' : 'hide'">
					<text class="indicator-text">Loading ...</text>
					<loading-indicator class="indicator"></loading-indicator>
			</loading>
		</scroller>
		<!-- </scroll-div> -->
	</div>
</template>
<script>
import { cardBillList, list } from '../../../api/card';
import myNavbar from '../../../components/myNavbar/myNavbar.vue'
export default {
	name: '',
	components: {
	    myNavbar
    },
	data() {
		return {
			balance: '0.00',
			showDetail: false,
			scrollData: [], //记录要滚动的数据
			loadinging: false,
			cardId: '',
			pageNum: 1,
			pageSize: 10,
			saveCardDetail: [
				{
					isIncome: false,
					icon: 'http://cdn.rzico.com/v4.0/wallet-consumption.png',
					tag: '购物消费',
					remark: '电冰箱',
					account: 300,
					date: '05-18 20:30:20',
					balance: 200
				},
				{
					isIncome: true,
					icon: 'http://cdn.rzico.com/v4.0/wallet-income.png',
					tag: '充值入账',
					remark: '五一节福利',
					account: 500,
					date: '05-18 20:30:20',
					balance: 200
				},
				{
					isIncome: false,
					icon: 'http://cdn.rzico.com/v4.0/wallet-timeout.png',
					tag: '购物消费',
					remark: '电冰箱',
					account: 300,
					date: '05-18 20:30:20',
					balance: 200
				},
				{
					isIncome: false,
					icon: 'http://cdn.rzico.com/v4.0/wallet-consumption.png',
					tag: '购物消费',
					remark: '电冰箱',
					account: 300,
					date: '05-18 20:30:20',
					balance: 200
				},
				{
					isIncome: true,
					icon: 'http://cdn.rzico.com/v4.0/wallet-income.png',
					tag: '充值入账',
					remark: '五一节福利',
					account: 500,
					date: '05-18 20:30:20',
					balance: 200
				},
				{
					isIncome: false,
					icon: 'http://cdn.rzico.com/v4.0/wallet-timeout.png',
					tag: '购物消费',
					remark: '电冰箱',
					account: 300,
					date: '05-18 20:30:20',
					balance: 200
				},
				{
					isIncome: false,
					icon: 'http://cdn.rzico.com/v4.0/wallet-consumption.png',
					tag: '购物消费',
					remark: '电冰箱',
					account: 300,
					date: '05-18 20:30:20',
					balance: 200
				},
				{
					isIncome: true,
					icon: 'http://cdn.rzico.com/v4.0/wallet-income.png',
					tag: '充值入账',
					remark: '五一节福利',
					account: 500,
					date: '05-18 20:30:20',
					balance: 200
				},
				{
					isIncome: false,
					icon: 'http://cdn.rzico.com/v4.0/wallet-timeout.png',
					tag: '购物消费',
					remark: '电冰箱',
					account: 300,
					date: '05-18 20:30:20',
					balance: 200
				}
			]
		};
	},
	created() {
		this.getCardList()
	},
	methods: {
		getCardList() {
			list({ cardType: 0, memberId: app.config.params.memberId }).then(res => {
				if (res.type == 'success') {
					if (res.data.data.length > 0) {
						this.balance = res.data.data[0].balance
						this.cardId = res.data.data[0].id
						this.showDetail = true
						this.getCardBill()
					} else {
						this.showDetail = false
						this.balance = '0.00'
					}
				}
			}).catch(() => {  });


		},
		getCardBill() {
			this.loadinging = true;
			let params = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				cardId: this.cardId,
			};
			cardBillList(params).then(res => {
				if (res.type == 'success') {
					res.data.data.forEach(item => {
						item.createDate = this.formatTime(item.createDate);
						item.account = (item.credit - item.debit).toFixed(2);
						item.balance = Number(item.balance).toFixed(2);
						if (item.type == 0) {
							item.tag = '充值-';
							item.isIncome = true;
							item.icon = 'http://cdn.rzico.com/v4.0/wallet-income.png';
						} else if (item.type == 2) {
							item.tag = '';
							item.isIncome = true;
							item.icon = 'http://cdn.rzico.com/v4.0/wallet-income.png';
						} else if (item.type == 1) {
							item.tag = '';
							item.isIncome = false;
							item.icon = 'http://cdn.rzico.com/v4.0/wallet-consumption.png';
						}
						this.saveCardDetail.push(item)
					})
					eeui.loadingClose();
					this.loadinging = false;
				}
			}).catch(() => { this.loadinging = false })
		},

		// 触底加载
		onloading() {
			if (this.loadinging == false) {
				this.pageNum += 1;
				// modal.toast({ message: '加载中', duration: 1 });
				eeui.loading();
				this.getCardBill();
			}
		}
	}
};
</script>

<style scoped>
.page-navbar {
	width: 750px;
	height: 90px;
}
.page-navbar-title {
	color: #ffffff;
	font-size: 28px;
}

.saveCard-top {
	width: 750px;
	background-color: #fcf8f5;
	align-items: center;
	padding: 50px 0 20px 0;
}

.saveCard-bg {
	position: relative;
	width: 620px;
	height: 330px;
	margin: 0 auto;
	/* border: 1px solid rgba(127, 91, 36, 1); */
	border-radius: 32px;
	background-image: linear-gradient(to top right, #27262b, #434041);
}

.saveCard-bg-image {
	position: absolute;
	top: 2px;
	left: 2px;
	width: 620px;
	height: 330px;
}

.saveCard-text1 {
	position: absolute;
	font-size: 30px;
	font-family: STSongti;
	font-weight: 900;
	color: #e0b243;
	line-height: 42px;
	/* text-shadow: 1px 1px 0px rgba(255, 255, 255, 0.3); */
	z-index: 100;
	left: 50px;
	top: 50px;
}

.saveCard-text2 {
	position: absolute;
	font-size: 42px;
	font-family: PingFangSC;
	font-weight: bold;
	color: #e0b243;
	line-height: 42px;
	z-index: 100;
	top: 155px;
	/* text-shadow: 1px 1px 0px rgba(255, 255, 255, 0.3); */
	left: 50px;
}

.saveCard-text2 text {
	font-size: 30px;
}

.saveCard-text3 {
	position: absolute;
	font-size: 20px;
	font-family: STSongti;
	font-weight: 900;
	color: #7a4a00;
	line-height: 42px;
	text-shadow: 1px 1px 0px rgba(255, 255, 255, 0.3);
	z-index: 100;
	right: 30px;
	bottom: 30px;
}

.saveCard-bottom {
	font-size: 32px;
	/* margin-top: 20px; */
	/* background-image: linear-gradient(to top, #FF560C , #FE8003); */
	border-radius: 16px;
	letter-spacing: 5px;
	padding: 0 30px;
}

.saveCard-bottom-list {
	display: flex;
	flex-direction: row;
	align-items: center;
	height: 125px;
}

.bottom-item {
	width: 604px;
	display: flex;
	justify-content: center;
}

.saveCard-bottom-list-image {
	width: 66px;
	height: 66px;
	margin-right: 20px;
}

.saveCard-bottom-list-top {
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: center;
	padding-bottom: 5rpx;
}

.saveCard-bottom-list-top1 {
	font-size: 28px;
	font-family: PingFangSC;
	font-weight: 400;
	color: #1a1a1e;
	/* border: #6d9584 solid 1px; */
	/* height: 40px; */
	width: 450px;
	display: -webkit-box;
	word-break: break-all;
	-webkit-box-orient: vertical;
	text-overflow: ellipsis;
	overflow: hidden;
	lines: 2;
}

.saveCard-bottom-list-top2 {
	font-size: 24px;
	font-family: PingFangSC;
	font-weight: bold;
	color: #1a1a1e;
}

.redColor {
	color: #ea716a;
}

.saveCard-bottom-list-bottom {
	/* padding-top: 10px; */
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
	font-size: 24px;
	font-family: PingFangSC;
	font-weight: 400;
	color: #1a1a1e;
	opacity: 0.3;
}

.saveCard-none {
	align-items: center;
	margin-top: 200px;
	width: 750px;
}

.saveCard-none-image {
	text-align: center;
	display: block;
	/* margin: 0 auto; */
	width: 196px;
	height: 131px;
}

.saveCard-none-text {
	text-align: center;
	letter-spacing: 5px;
	font-size: 28px;
	font-family: PingFang SC;
	font-weight: 400;
	color: rgba(26, 26, 30, 1);
	line-height: 42px;
	opacity: 0.3;
	margin-top: 30px;
}

.loading {
	width: 750px;
	display: -ms-flex;
	display: -webkit-flex;
	display: flex;
	-ms-flex-align: center;
	-webkit-align-items: center;
	-webkit-box-align: center;
	align-items: center;
}
.indicator {
	margin-top: 16px;
	height: 40px;
	width: 40px;
	color: blue;
}
</style>
